import 'package:json_annotation/json_annotation.dart';

import 'package_group.dart';

part 'packing_data.g.dart';

@JsonSerializable()
class PackingData extends Object {
  @JsonKey(name: 'commodityFormList')
  List<CommodityFormList> commodityFormList;

  @JsonKey(name: 'costAmount')
  int costAmount;

  @JsonKey(name: 'settingId')
  int settingId;

  @JsonKey(name: 'targetValue')
  int targetValue;

  String get commodityName {
    var temp = '';
    commodityFormList.forEach((item) {
      temp += item.commodityNameWithSku;

      if (commodityFormList.last != item) {
        temp += ';';
      }
    });

    return temp;
  }

  PackingData(
    this.commodityFormList,
    this.costAmount,
    this.settingId,
    this.targetValue,
  );

  factory PackingData.fromJson(Map<String, dynamic> srcJson) => _$PackingDataFromJson(srcJson);

  Map<String, dynamic> toJson() => _$PackingDataToJson(this);
}
